
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>使用Rasterio做投影变换 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="使用Rasterio创建栅格数据.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../Python基础/">
            
                <a href="../../Python基础/">
            
                    
                    Python基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../Python基础/Python环境搭建及基本数据类型.html">
            
                <a href="../../Python基础/Python环境搭建及基本数据类型.html">
            
                    
                    Python环境搭建及基本数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../Python基础/运算符及字符串.html">
            
                <a href="../../Python基础/运算符及字符串.html">
            
                    
                    运算符及字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../Python基础/序列与字典.html">
            
                <a href="../../Python基础/序列与字典.html">
            
                    
                    序列与字典
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../Python基础/流程控制语句.html">
            
                <a href="../../Python基础/流程控制语句.html">
            
                    
                    流程控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../../Python基础/函数.html">
            
                <a href="../../Python基础/函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../../Python基础/面向对象编程初识.html">
            
                <a href="../../Python基础/面向对象编程初识.html">
            
                    
                    面向对象编程初识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../../Python基础/面向对象编程高级.html">
            
                <a href="../../Python基础/面向对象编程高级.html">
            
                    
                    面向对象编程高级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../../Python基础/Python科学计算.html">
            
                <a href="../../Python基础/Python科学计算.html">
            
                    
                    Python科学计算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../../Python基础/空间数据处理环境搭建.html">
            
                <a href="../../Python基础/空间数据处理环境搭建.html">
            
                    
                    空间数据处理环境搭建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../空间数据基础/">
            
                <a href="../../空间数据基础/">
            
                    
                    空间数据基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../空间数据基础/空间参考系统.html">
            
                <a href="../../空间数据基础/空间参考系统.html">
            
                    
                    空间参考系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../空间数据基础/地图投影.html">
            
                <a href="../../空间数据基础/地图投影.html">
            
                    
                    地图投影
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../空间数据基础/空间数据.html">
            
                <a href="../../空间数据基础/空间数据.html">
            
                    
                    空间数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../">
            
                <a href="../">
            
                    
                    GDAL空间数据处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../GDAL简介.html">
            
                <a href="../GDAL简介.html">
            
                    
                    GDAL简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../GDAL数据基本操作.html">
            
                <a href="../GDAL数据基本操作.html">
            
                    
                    GDAL数据基本操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../GDAL数据基本操作/打开栅格数据的正确方式.html">
            
                <a href="../GDAL数据基本操作/打开栅格数据的正确方式.html">
            
                    
                    打开栅格数据的正确方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="../GDAL数据基本操作/栅格数据格式转换.html">
            
                <a href="../GDAL数据基本操作/栅格数据格式转换.html">
            
                    
                    栅格数据格式转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.3" data-path="../GDAL数据基本操作/栅格数据创建与保存.html">
            
                <a href="../GDAL数据基本操作/栅格数据创建与保存.html">
            
                    
                    栅格数据创建与保存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.4" data-path="../GDAL数据基本操作/读取HDF或者NetCDF格式的栅格数据.html">
            
                <a href="../GDAL数据基本操作/读取HDF或者NetCDF格式的栅格数据.html">
            
                    
                    读取HDF或者NetCDF格式的栅格数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.5" data-path="../GDAL数据基本操作/栅格数据投影转换.html">
            
                <a href="../GDAL数据基本操作/栅格数据投影转换.html">
            
                    
                    栅格数据投影转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.6" data-path="../GDAL数据基本操作/栅格数据裁剪.html">
            
                <a href="../GDAL数据基本操作/栅格数据裁剪.html">
            
                    
                    栅格数据裁剪
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.7" data-path="../GDAL数据基本操作/打开Shapefile文件的正确方式.html">
            
                <a href="../GDAL数据基本操作/打开Shapefile文件的正确方式.html">
            
                    
                    打开Shapefile文件的正确方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.8" data-path="../GDAL数据基本操作/创建Shapefile文件并写入数据.html">
            
                <a href="../GDAL数据基本操作/创建Shapefile文件并写入数据.html">
            
                    
                    创建Shapefile文件并写入数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.9" data-path="../GDAL数据基本操作/矢量数据投影转换.html">
            
                <a href="../GDAL数据基本操作/矢量数据投影转换.html">
            
                    
                    矢量数据投影转换
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Fiona矢量数据处理/REDAME.md">
            
                <span>
            
                    
                    Fiona矢量数据处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.3.1" data-path="../Fiona矢量数据处理/Fiona简介及Shapefile数据读取.html">
            
                <a href="../Fiona矢量数据处理/Fiona简介及Shapefile数据读取.html">
            
                    
                    Fiona简介及Shapefile数据读取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3.2" data-path="../Fiona矢量数据处理/使用Fiona创建Shapefile矢量数据.html">
            
                <a href="../Fiona矢量数据处理/使用Fiona创建Shapefile矢量数据.html">
            
                    
                    使用Fiona创建Shapefile矢量数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="README.md">
            
                <span>
            
                    
                    Rasterio栅格数据处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.4.1" data-path="使用Rasterio读取栅格数据.html">
            
                <a href="使用Rasterio读取栅格数据.html">
            
                    
                    使用Rasterio读取栅格数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4.2" data-path="使用Rasterio创建栅格数据.html">
            
                <a href="使用Rasterio创建栅格数据.html">
            
                    
                    使用Rasterio创建栅格数据
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.4.3" data-path="使用Rasterio做投影变换.html">
            
                <a href="使用Rasterio做投影变换.html">
            
                    
                    使用Rasterio做投影变换
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >使用Rasterio做投影变换</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x4F7F;&#x7528;rasterio&#x505A;&#x6295;&#x5F71;&#x53D8;&#x6362;">&#x4F7F;&#x7528;Rasterio&#x505A;&#x6295;&#x5F71;&#x53D8;&#x6362;</h1>
<p>&#x4F5C;&#x8005;&#xFF1A;&#x963F;&#x632F;</p>
<p>&#x90AE;&#x7BB1;&#xFF1A;tanzhenyugis@163.com</p>
<p>&#x535A;&#x5BA2;&#xFF1A;<a href="https://blog.csdn.net/theonegis/article/details/80089375" target="_blank">https://blog.csdn.net/theonegis/article/details/80089375</a></p>
<p>&#x4FEE;&#x6539;&#x65F6;&#x95F4;&#xFF1A;2018-06-11</p>
<p>&#x58F0;&#x660E;&#xFF1A;&#x672C;&#x6587;&#x4E3A;&#x535A;&#x4E3B;&#x539F;&#x521B;&#x6587;&#x7AE0;&#xFF0C;&#x8F6C;&#x8F7D;&#x8BF7;&#x6CE8;&#x660E;&#x539F;&#x6587;&#x51FA;&#x5904;</p>
<hr>
<h2 id="&#x601D;&#x8DEF;&#x5206;&#x6790;">&#x601D;&#x8DEF;&#x5206;&#x6790;</h2>
<p>&#x5728;&#x4E4B;&#x524D;GDAL&#x7CFB;&#x5217;&#x6587;&#x7AE0;&#x4E2D;&#x7684;&#x300A;<a href="https://blog.csdn.net/theonegis/article/details/80543988" target="_blank">&#x6805;&#x683C;&#x6570;&#x636E;&#x6295;&#x5F71;&#x8F6C;&#x6362;</a>&#x300B;&#x63D0;&#x5230;&#x8FC7;&#xFF0C;&#x505A;&#x6295;&#x5F71;&#x8F6C;&#x6362;&#x6700;&#x91CD;&#x8981;&#x7684;&#x662F;&#x8BA1;&#x7B97;&#x6570;&#x636E;&#x5728;&#x76EE;&#x6807;&#x7A7A;&#x95F4;&#x53C2;&#x8003;&#x7CFB;&#x7EDF;&#x4E2D;&#x7684;&#x653E;&#x5C04;&#x53D8;&#x6362;&#x53C2;&#x6570;&#xFF08;GeoTransform&#xFF09;&#x548C;&#x56FE;&#x50CF;&#x7684;&#x5C3A;&#x5BF8;&#xFF08;&#x884C;&#x6570;&#x548C;&#x5217;&#x6570;&#xFF09;&#x3002;&#x800C;&#x4E14;&#x6211;&#x4EEC;&#x4F7F;&#x7528;GDAL&#x57FA;&#x672C;&#x5E93;&#x81EA;&#x5DF1;&#x5199;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4E86;&#x8BA1;&#x7B97;&#x3002;</p>
<p>&#x5728;rasterio&#x4E2D;&#x63D0;&#x4F9B;&#x4E86;<code>calculate_default_transform</code>&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8BA1;&#x7B97;&#x76EE;&#x6807;&#x7CFB;&#x7EDF;&#x4E2D;&#x7684;&#x653E;&#x5C04;&#x53D8;&#x6362;&#x53C2;&#x6570;&#x548C;&#x56FE;&#x50CF;&#x5C3A;&#x5BF8;&#x3002;</p>
<p>&#x8FD9;&#x6837;&#x6211;&#x4EEC;&#x76F4;&#x63A5;&#x6839;&#x636E;&#x8BA1;&#x7B97;&#x7684;&#x7ED3;&#x679C;&#x66F4;&#x65B0;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x7684;&#x5143;&#x4FE1;&#x606F;&#x5373;&#x53EF;&#x3002;</p>
<h2 id="&#x4EE3;&#x7801;&#x5B9E;&#x73B0;">&#x4EE3;&#x7801;&#x5B9E;&#x73B0;</h2>
<pre><code class="lang-Python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> rasterio
<span class="hljs-keyword">from</span> rasterio.warp <span class="hljs-keyword">import</span> calculate_default_transform, reproject, Resampling
<span class="hljs-keyword">from</span> rasterio <span class="hljs-keyword">import</span> crs

src_img = <span class="hljs-string">&apos;example.tif&apos;</span>
dst_img = <span class="hljs-string">&apos;reproject.tif&apos;</span>

<span class="hljs-comment"># &#x8F6C;&#x4E3A;&#x5730;&#x7406;&#x5750;&#x6807;&#x7CFB;WGS84</span>
dst_crs = crs.CRS.from_epsg(<span class="hljs-string">&apos;4326&apos;</span>)


<span class="hljs-keyword">with</span> rasterio.open(src_img) <span class="hljs-keyword">as</span> src_ds:
    profile = src_ds.profile

    <span class="hljs-comment"># &#x8BA1;&#x7B97;&#x5728;&#x65B0;&#x7A7A;&#x95F4;&#x53C2;&#x8003;&#x7CFB;&#x4E0B;&#x7684;&#x4EFF;&#x5C04;&#x53D8;&#x6362;&#x53C2;&#x6570;&#xFF0C;&#x56FE;&#x50CF;&#x5C3A;&#x5BF8;</span>
    dst_transform, dst_width, dst_height = calculate_default_transform(
        src_ds.crs, dst_crs, src_ds.width, src_ds.height, *src_ds.bounds)

    <span class="hljs-comment"># &#x66F4;&#x65B0;&#x6570;&#x636E;&#x96C6;&#x7684;&#x5143;&#x6570;&#x636E;&#x4FE1;&#x606F;</span>
    profile.update({
        <span class="hljs-string">&apos;crs&apos;</span>: dst_crs,
        <span class="hljs-string">&apos;transform&apos;</span>: dst_transform,
        <span class="hljs-string">&apos;width&apos;</span>: dst_width,
        <span class="hljs-string">&apos;height&apos;</span>: dst_height,
        <span class="hljs-string">&apos;nodata&apos;</span>: <span class="hljs-number">0</span>
    })

    <span class="hljs-comment"># &#x91CD;&#x6295;&#x5F71;&#x5E76;&#x5199;&#x5165;&#x6570;&#x636E;</span>
    <span class="hljs-keyword">with</span> rasterio.open(dst_img, <span class="hljs-string">&apos;w&apos;</span>, **profile) <span class="hljs-keyword">as</span> dst_ds:
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>, src_ds.count + <span class="hljs-number">1</span>):
            src_array = src_ds.read(i)
            dst_array = np.empty((dst_height, dst_width), dtype=profile[<span class="hljs-string">&apos;dtype&apos;</span>])

            reproject(
                <span class="hljs-comment"># &#x6E90;&#x6587;&#x4EF6;&#x53C2;&#x6570;</span>
                source=src_array,
                src_crs=src_ds.crs,
                src_transform=src_ds.transform,
                <span class="hljs-comment"># &#x76EE;&#x6807;&#x6587;&#x4EF6;&#x53C2;&#x6570;</span>
                destination=dst_array,
                dst_transform=dst_transform,
                dst_crs=dst_crs,
                <span class="hljs-comment"># &#x5176;&#x5B83;&#x914D;&#x7F6E;</span>
                resampling=Resampling.cubic,
                num_threads=<span class="hljs-number">2</span>)

            dst_ds.write(dst_array, i)
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="使用Rasterio创建栅格数据.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 使用Rasterio创建栅格数据">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"使用Rasterio做投影变换","level":"1.4.4.3","depth":3,"previous":{"title":"使用Rasterio创建栅格数据","level":"1.4.4.2","depth":3,"path":"GDAL空间数据处理/Rasterio栅格数据处理/使用Rasterio创建栅格数据.md","ref":"GDAL空间数据处理/Rasterio栅格数据处理/使用Rasterio创建栅格数据.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"GDAL空间数据处理/Rasterio栅格数据处理/使用Rasterio做投影变换.md","mtime":"2019-03-22T18:52:30.714Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-03-22T20:04:12.549Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

